package com.struts.deal.admin.corpor;


import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibatis.po.corpor.TCorporation;
import com.ibatis.po.corpor.TIssueposition;
import com.ibatis.po.corpor.TIssuepositionExample;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.lg.system.CSqlMap;
import com.lg.system.CTurnPage;
import com.struts.web.corpor.manage.infomanage.PositionBean;
import com.struts.web.corpor.manage.infomanage.ViewCorporInfoBean;
import com.struts.web.corpor.manage.infomanage.ViewCorporInfoForm;
import com.struts.web.manage.admin.corpor.ApproveCorporForm;
import com.struts.web.manage.admin.corpor.QueryBlackForm;

public class Deal {
    /**
     * 查询黑名单
     * @param request
     * @param aWebForm
     */
	public static void queryBlackList(HttpServletRequest request,QueryBlackForm aWebForm){
		String corporName = "";
		TCorporation corporPo= new TCorporation();
		try{
			if(aWebForm.getCorporName()!=null && aWebForm.getCorporName().length()>1){
				corporName = aWebForm.getCorporName();
			}
			corporPo.setCorporationName(corporName);
		CTurnPage page = new CTurnPage();
		page.setQueryList("T_CORPORATION.selectBlackList",corporPo);
		page.setPerPageRows(10);
		page.excute(request);
		request.setAttribute("page", page);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 修改黑名单状态
	 * @param request
	 * @param aWebForm
	 */
	public static boolean editBlack(HttpServletRequest request,QueryBlackForm aWebForm) throws SQLException{
		TCorporation corporPo= new TCorporation();
		boolean result = false;
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		String corporId = request.getParameter("ID");
		try{
			if(corporId!=null && corporId.length()>0){
			corporPo.setId(corporId);
			if(aWebForm.getStatus()!=null && aWebForm.getStatus().length()>0){
			corporPo.setBlackList(aWebForm.getStatus());
			
			sqlmap.update("T_CORPORATION.updateBlackList",corporPo);
			result = true;
			}
			}
		
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}
	
	/**
	 * 加载黑名单状态
	 * @param request
	 * @param aWebForm
	 */
	public static boolean doEditBlackDefault(HttpServletRequest request,QueryBlackForm aWebForm){
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TCorporation corporPo= new TCorporation();
		boolean result = false;
		String corporId = request.getParameter("ID");
		try{
			corporPo.setId(corporId);
			corporPo = (TCorporation)sqlmap.queryForObject("T_CORPORATION.abatorgenerated_selectByPrimaryKey",corporPo);
			aWebForm.setCorporName(corporPo.getCorporationName());
			aWebForm.setStatus(corporPo.getBlackList());
			result = true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}
	
	/**
     * 查询推荐企业
     * @param request
     * @param aWebForm
     */
	public static void queryRecommend(HttpServletRequest request,QueryBlackForm aWebForm){
		String corporName = "";
		TCorporation corporPo= new TCorporation();
		try{
			if(aWebForm.getCorporName()!=null && aWebForm.getCorporName().length()>0){
				corporName = aWebForm.getCorporName();
			}
			corporPo.setCorporationName(corporName);
		CTurnPage page = new CTurnPage();
		page.setQueryList("T_CORPORATION.selectRecommendForEdit",corporPo);
		page.setPerPageRows(10);
		page.excute(request);
		request.setAttribute("page", page);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	/**
	 * 修改企业推荐状态
	 * @param request
	 * @param aWebForm
	 */
	public static boolean editRecommend(HttpServletRequest request,QueryBlackForm aWebForm) throws SQLException{
		TCorporation corporPo= new TCorporation();
		boolean result = false;
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		String corporId = request.getParameter("ID");
		try{
			if(corporId!=null && corporId.length()>0){
			corporPo.setId(corporId);
			if(aWebForm.getStatus()!=null && aWebForm.getStatus().length()>0){
				System.out.println("44444444444444"+aWebForm.getStatus());
			corporPo.setIsrecommend(aWebForm.getStatus());
			
			sqlmap.update("T_CORPORATION.updateRecommend",corporPo);
			result = true;
			}
			}
		
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}
	
	/**
	 * 加载企业推荐状态
	 * @param request
	 * @param aWebForm
	 */
	public static boolean doEditRecommendDefault(HttpServletRequest request,QueryBlackForm aWebForm){
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TCorporation corporPo= new TCorporation();
		boolean result = false;
		String corporId = request.getParameter("ID");
		try{
			corporPo.setId(corporId);
			corporPo = (TCorporation)sqlmap.queryForObject("T_CORPORATION.abatorgenerated_selectByPrimaryKey",corporPo);
			aWebForm.setCorporName(corporPo.getCorporationName());
			aWebForm.setStatus(corporPo.getIsrecommend());
			result = true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}
	
	/**
     * 企业批准列表查询
     * @param request
     * @param aWebForm
     */
	public static void queryApproveCorpor(HttpServletRequest request,ApproveCorporForm aWebForm){
		
		TCorporation corporPo= new TCorporation();
		try{
			if(aWebForm.getCorporName()!=null && aWebForm.getCorporName()!=""){
				corporPo.setCorporationName(aWebForm.getCorporName());
			}
			if(aWebForm.getStatus()!=null && aWebForm.getStatus()!=""){
				corporPo.setStatus(aWebForm.getStatus());
			}
			if(aWebForm.getCorportype()!=null && aWebForm.getCorportype()!=""){
				corporPo.setKindId(aWebForm.getCorportype());
			}
			if(aWebForm.getCorporId()!=null && aWebForm.getCorporId()!=""){
				corporPo.setId(aWebForm.getCorporId());
				System.out.println("ffffff");
			}
		CTurnPage page = new CTurnPage();
		page.setQueryList("T_CORPORATION.selectApproveCorpor",corporPo);
		page.setPerPageRows(10);
		page.excute(request);
		request.setAttribute("page", page);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	
	
	/**
     * 企业批准
     * @param request
     * @param aWebForm
     */
	public static boolean editApproveCorpor(HttpServletRequest request,ApproveCorporForm aWebForm) throws SQLException{
		boolean result = false;
		String corporId = request.getParameter("corporId");
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		TCorporation corporPo= new TCorporation();
		try{
			if(corporId!="" && corporId!=null){
				corporPo.setId(corporId);
				corporPo.setStatus(aWebForm.getStatus());
				
				sqlmap.update("T_CORPORATION.approveCorpor",corporPo);
	
				result = true;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}
	

	
	/**
	 * 企业批准信息加载
	 * @param request
	 * @param response
	 * @param aWebForm
	 * @return
	 * @throws SQLException
	 */
	public static boolean loadApproveCorpor(HttpServletRequest request,
            HttpServletResponse response,ApproveCorporForm aWebForm) throws SQLException{
		boolean result = false;
		String corporId = request.getParameter("corporId");
		request.setAttribute("corporId", corporId);
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		ViewCorporInfoBean vBean = new ViewCorporInfoBean();
		try{
			if(corporId!="" && corporId!=null){
				vBean = (ViewCorporInfoBean)sqlmap.queryForObject("T_CORPORATION.selectViewInfo",corporId);
				aWebForm.getCorporFormBean().setCorporationName(vBean.getCorporationName());
				aWebForm.getCorporFormBean().setKindofname(vBean.getKindofname());
				aWebForm.getCorporFormBean().setCityname(vBean.getCityname());
				aWebForm.getCorporFormBean().setHomepage(vBean.getHomepage());
				aWebForm.getCorporFormBean().setContactPerson(vBean.getContactPerson());
				aWebForm.getCorporFormBean().setTelephone(vBean.getTelephone());
				aWebForm.getCorporFormBean().setMobilphone(vBean.getMobilphone());
				aWebForm.getCorporFormBean().setContactAddress(vBean.getContactAddress());
				aWebForm.getCorporFormBean().setCorporationSynopsis(vBean.getCorporationSynopsis());
				aWebForm.setStatus(vBean.getIsRecommend());
				System.out.println("ffff:"+aWebForm.getStatus());
				aWebForm.setStatus(vBean.getStatus());
				result = true;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return result;
	}
}
